﻿using System;
using System.IO;
using ConsoleTools;
using System.Collections.Generic;
using System.Linq;

namespace movefiles
{
    class Program
    {
        static string currentDirectory;
        static void Main(string[] args)
        {
            var arguments = CommandLineArgumentParser.Parse(args);
            if (arguments.Has("-f"))
            {
                string path = arguments.Get("-f").Next;

                Console.WriteLine("文件路径：{0}", path);
                string[] directorys = Directory.GetDirectories(path);
                string[] files = Directory.GetDirectories(path);

                var directoryInfo = new DirectoryInfo(path);
                DirectoryInfo[] directoryInfos = directoryInfo.GetDirectories();

                
            } else {
                 
                currentDirectory = Directory.GetCurrentDirectory();
                //currentDirectory = "G:\\新建文件夹";
                Console.Write("当前路径是：{0}",currentDirectory);
                Console.WriteLine(Path.GetFileName(currentDirectory));
                 
                Move(currentDirectory);
                Console.ReadLine();
                

            }


            Console.ReadLine();
        }
        static  void Move(string path)
        {
            try
            {
                if (File.Exists(path))
                {

                    Console.WriteLine("文件路径{0}", path);
                    //string filename = Path.GetFileName(path);
                    //var fileInfo = Directory.GetParent(path);
                    //var folderName = Path.GetFileName(fileInfo.ToString());
                    // Ensure that the target does not exist.
                    if (File.Exists(currentDirectory + '/' + Path.GetFileName(path)))
                    {
                        File.Delete(currentDirectory + '/' + Path.GetFileName(path));

                    }
                    File.Move(path, currentDirectory + '/' + Path.GetFileName(path));

                }
                if (Directory.Exists(path)&&path!= currentDirectory)
                {
                    Console.WriteLine("路径{0}", path);
                    string[] directories = Directory.GetDirectories(path);
                    string[] files = Directory.GetFiles(path);

                    foreach (string directory in directories)
                    {
                        Move(directory);
                    }

                    foreach (string file in files)
                    {
                        Move(file);
                    }
                }
            } catch(Exception e)
            {
                Console.WriteLine("The process failed: {0}", e.ToString());
            }
          
        }
    }
}
